<template>
    <div>
        <!-- 面包屑导航区域 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图区域 -->
        <el-card>
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getorderList">
                        <el-button slot="append" icon="el-icon-search" @click="getorderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 表格区域 -->
            <el-table :data="OrderTableList" border stripe>
                <el-table-column type="index"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"></el-table-column>
                <el-table-column prop="pay_status" label="是否付款">
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.pay_status==='0'">未付款</el-tag>
                        <el-tag type="success" v-else-if="scope.row.pay_status==='1'">已付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货"></el-table-column>
                <el-table-column prop="create_time" label="下单时间">
                    <template slot-scope="scope">
                        {{scope.row.create_time | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" icon="el-icon-edit" @click="editOrder"></el-button>
                        <el-button size="mini" type="success" icon="el-icon-location" @click="showProgress"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页区域 -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15]" :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
        <!-- 编辑按钮弹出的对话框 -->
        <el-dialog title="修改地址" :visible.sync="editdialogVisible" width="50%" @close="closeDialog">
            <!-- 主体区域 -->
            <el-form :model="editForm" :rules="editFormRules" ref="ruleFormRef" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <!-- 级联选择器 -->
                    <el-cascader expand-trigger="hover" v-model="editForm.address1" :options="cityData"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="editForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editdialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="editdialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 展示物流进度的对话框 -->
        <el-dialog title="物流进度" :visible.sync="ProgressdialogVisible" width="50%">
            <!-- 时间线 -->
            <el-timeline>
                <el-timeline-item v-for="(activity, index) in ProgressList" :key="index" :timestamp="activity.time">
                    {{activity.context}}
                </el-timeline-item>
            </el-timeline>

        </el-dialog>
    </div>
</template>
<script>
    //导入省市区县js文件
    import cityData from '../../assets/js/citydata'
    export default {
        data() {
            return {
                //订单列表的查询参数对象
                queryInfo: {
                    //查询条件
                    query: '',
                    pagenum: 1,
                    pagesize: 10,

                },
                //订单数据列表表格数据
                OrderTableList: [],
                //订单数据列表总的数据条数
                total: 0,
                //控制编辑按钮对话框的显示与隐藏
                editdialogVisible: false,
                //编辑表单的数据对象
                editForm: {
                    address1: [],
                    address2: '',

                },
                //编辑表单的验证规则对象
                editFormRules: {
                    address1: [{
                        required: true,
                        message: '请选择省市区县',
                        trigger: 'blur'
                    }, ],
                    address2: [{
                        required: true,
                        message: '请填写详细地址',
                        trigger: 'blur'
                    }, ]

                },
                //级联选择器省市区县的js文件
                cityData,
                //控制物流进度对话框的显示与隐藏
                ProgressdialogVisible: false,
                //存放物流进度的数组数据
                ProgressList:[],

            }
        },
        created() {
            this.getorderList();

        },
        methods: {
            //获取订单列表数据
            async getorderList() {
                const {
                    data: res
                } = await this.$http.get('orders', {
                    params: this.queryInfo
                });
                console.log(res);
                if (res.meta.status !== 200) {
                    return this.$message.error('获取订单列表数据失败');
                }
                this.OrderTableList = res.data.goods;
                this.total = res.data.total;
            },
            //每页几条数据发生变化出发的事件
            handleSizeChange(newsize) {
                this.queryInfo.pagesize = newsize;
                this.getorderList();

            },
            //当前是第几页发生变化触发的事件
            handleCurrentChange(newpage) {
                this.queryInfo.pagenum = newpage;
                this.getorderList();

            },
            //点击订单列表的编辑按钮
            editOrder() {
                this.editdialogVisible = true;
            },
            //关闭编辑对话框，清空表单
            closeDialog() {
                this.$refs.ruleFormRef.resetFields();
            },
            //展示物流进度的按钮
            async showProgress() {
                //发起请求，获取物流进度数据
                const {
                    data: res
                } = await this.$http.get('/kuaidi/1106975712662');
                console.log(res, "111");
                if (res.meta.status !== 200) {
                    return this.$message.error('获取物流进度失败')
                }
                this.ProgressList = res.data;
                this.ProgressdialogVisible = true;

            }






        }
    }
</script>
<style lang="less" scoped>
    .el-cascader {
        width: 100%;
    }
</style>